package com.syas.service.services;

import com.syas.base.service.services.EntityService;
import com.syas.common.utilities.PageList;
import com.syas.common.utilities.PageListUtil;
import com.syas.dao.interfaces.IGradeDao;
import com.syas.model.models.Account;
import com.syas.model.models.Grade;
import com.syas.service.interfaces.IGradeService;
import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by weigong on 2015/12/5.
 */
@Service("GradeService")
public class GradeService extends EntityService<Integer, Grade, IGradeDao> implements IGradeService {


    @Autowired
    public GradeService(@Qualifier("GradeDao") IGradeDao  gradeDao) {
        super(gradeDao);
    }

    @Override
    public List<Grade> getGradeList() {
        return entityDao.getGradeList();
    }

    @Override
    public List<Grade> getStationList() {
        return entityDao.getGradeList();
    }

    @Override
    public PageList<Grade> listGradePage(int pageNo, int pageSize) {
        Criteria countCriteria = entityDao.getCriteria();
        Criteria listCriteria = entityDao.getCriteria();
        listCriteria.setFirstResult((pageNo - 1) * pageSize);
        listCriteria.setMaxResults(pageSize);
        List<Grade> items = listCriteria.list();
        countCriteria.setProjection(Projections.rowCount());
        Integer count = Integer.parseInt(countCriteria.uniqueResult().toString());
        return PageListUtil.getPageList(count, pageNo, items, pageSize);
    }
}
